package org.gcu.filestorage.serive;

import lombok.extern.slf4j.Slf4j;
import org.gcu.filestorage.mapper.AccountInfoDao;
import org.gcu.filestorage.mapper.AccountInfoMapper;
import org.gcu.filestorage.pojo.AccountInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class AccountInfoServiceImpl implements AccountInfoService {

    private final AccountInfoMapper accountInfoMapper;

    private final AccountInfoDao accountInfoDao;

    @Autowired
    public AccountInfoServiceImpl(AccountInfoMapper accountInfoMapper, AccountInfoDao accountInfoDao) {
        this.accountInfoMapper = accountInfoMapper;
        this.accountInfoDao = accountInfoDao;
    }

    @Override
    public boolean insertNewAccountInfo(AccountInfo newAccountInfo) {
        return this.accountInfoDao.insert(newAccountInfo) > 0;
    }

    @Override
    public AccountInfo queryAccountInfo(String account) {
        return this.accountInfoMapper.queryAccountInfo(account);
    }

    @Override
    public List<AccountInfo> queryAccountInfoByPhoneNo(String phoneNo) {
        return this.accountInfoMapper.queryAccountInfoByPhoneNo(phoneNo);
    }

    @Override
    public List<AccountInfo> queryAccountInfoByEmail(String eMail) {
        return this.accountInfoMapper.queryAccountInfoByEmail(eMail);

    }

    @Override
    public List<AccountInfo> queryAccountInfoByEmployeeId(String employeeId) {
        return this.accountInfoMapper.queryAccountInfoByEmployeeId(employeeId);
    }

    @Override
    public List<AccountInfo> queryAccountInfoByStatus(int registerStatus) {
        return this.accountInfoMapper.queryAccountInfoByStatus(registerStatus);
    }

    @Override
    public boolean updateRegisterStatus(String account, int registerStatus) {
        int count = this.accountInfoMapper.updateRegisterStatus(account, registerStatus);
        log.info("updateRegisterStatus(), account=" + account + ", registerStatus=" + registerStatus + ",count=" + count);
        return count > 0;
    }

    @Override
    public boolean deleteAccountInfo(String account) {
        int count = this.accountInfoMapper.deleteAccountInfo(account);
        log.info("deleteAccountInfo(), account=" + account + ",count=" + count);
        return count > 0;
    }

    @Override
    public boolean updatePassword(String account, String password) {
        int count = this.accountInfoMapper.updatePassword(account, password);
        log.info("updatePassword(), account=" + account + ", password=" + password + ",count=" + count);
        return count > 0;
    }

}
